import {lookUp} from "./utils";

export default function renderTemplate(tokens, data) {
    let domStr = '';

    tokens.forEach(token => {
        const type = token[0];
        const value = token[1];

        switch (type) {
            case '#':
                lookUp(data, value).forEach((childData) => {
                    domStr += renderTemplate(token[2], childData);
                });
                break;
            case 'name':
                domStr += lookUp(data, value);
                break;
            case 'text':
                domStr += value;
                break;
        }
    });

    return domStr;
};